<!-- 参考官方文档 -->
<template>
    <view class="">
        <button @click="setStorageSync">增加</button>
        <button @click="getStorageSync">获取</button>
        <button @click="getStorageInfoSync">获取所有</button>
        <button @click="removeStorage">删除</button>
        <button @click="clearStorage">全部删除</button>
    </view>
</template>

<script lang="ts" setup>
    import { ref } from 'vue';

    let name = ref("");
    let data : UniApp.GetStorageInfoSuccess;

    function setStorageSync() {
        //增加缓存，同步
        uni.setStorageSync("code", "zs");
        uni.setStorageSync("name", "张三");
    };
    function getStorageSync() {
        //获取缓存，同步
        name = uni.getStorageSync("name");
        console.log(name);
    };
    function getStorageInfoSync() {
        //获取全部缓存，同步
        data = uni.getStorageInfoSync();
        console.log(data);
    };
    function removeStorage() {
        //删除缓存
        uni.removeStorage({
            key: "code"
        });
    };
    function clearStorage() {
        //删除所有缓存，同步
        uni.clearStorage();
    };
</script>

<style lang="scss" scoped>

</style>